<?php

namespace Common\Model;

/**
 * AuthorityLabelModel.class实例模型
 * 
 * @author songanwei
 * @date 2016-1-6
 */
class HotelAlarmClockModel extends BaseModel {

    protected $trueTableName = 'tb_hotel_alarm_clock';

    protected function _before_update(&$data, $options) {
    }

    /**
     * 根据客栈id获取内容
     * @modify wenhui 2017-07-28
     * @param int hotelId
     * @param int reminded 是否提醒
     * @param int newstype 是否已读
     * @return array data
     */
    public function getRemindListByHotel($hotelId, $reminded = null, $newstype = null) {
        if (is_array($hotelId)) {
            $hotelId = implode(',', $hotelId);
        }

        $option['isdelete'] = NOT_DELETE;
        if (strpos($hotelId, ',') !== false) {
            $option['hotelentity_id'] = array('in', $hotelId);
        } else {
            $option['hotelentity_id'] = $hotelId;
        }
        if (!is_null($reminded)) {
            $option['reminded'] = $reminded;
        }
        if (!is_null($newstype)) {
            $option['newstype'] = $newstype;
        }

        $data = $this->where($option)->select();
        return empty($data) ? array() : $data;
    }

    /**
     * 根据客栈id获取内容
     * @modify wenhui 2017-07-28
     * @param int alarmClockId
     * @return array data
     */
    public function getRemindById($alarmClockId) {

        $option['id'] = $alarmClockId;
        $data = $this->where($option)->find();

        return empty($data) ? array() : $data;
    }


    /**
     * 添加数据
     * @modify wenhui 2017-07-28
     * @param int hotelId
     * @param int remindDate
     * @param int content
     * @return int id
     */
    public function addRemind($hotelId, $remindDate, $content) {
        $data = array(
            'hotelentity_id' => $hotelId,
            'remindtime' => $remindDate,
            'content' => $content,
            'trueremindtime' => $remindDate,
        );

        $addResult = $this->add($data);
        return empty($addResult) ? array() : $addResult;
    }

    /**
     * 保存数据
     * @modify wenhui 2017-07-28
     * @param int hotelId
     * @param int remindDate
     * @param int content
     * @param int alarmClockId
     * @param int isRead
     * @return int id
     */
    public function saveRemind($hotelId, $remindDate, $content, $alarmClockId, $dropRemind, $isRead) {
        $option['id'] = $alarmClockId;

        $data = array();
        if (!empty($hotelId)) {
            $data['hotelentity_id'] = $hotelId;
        }
        if (!empty($remindDate)) {
            $data['remindtime'] = $remindDate;
        }
        if (!empty($content)) {
            $data['content'] = $content;
        }
        if (!empty($dropRemind)) {
            $data['isdelete'] = $dropRemind;
        }
        if (!empty($isRead)) {
            $data['newstype'] = $isRead;
        }

        $data['operator'] = getUserId();

        $saveResult = $this->where($option)->save($data);
        return $saveResult === false ? false : true;
    }

    /**
     * 设置提醒 0=未提醒 1=已提醒
     * @modify wenhui 2017-07-28
     * @param int alarmClockId
     */
    public function setRemind($alarmClockId) {
        $option = array(
            'id' => $alarmClockId,
        );
        $data['reminded'] = 1;
        $data['trueremindtime'] = date('Y-m-d H:i:s', time());

        $saveResult = $this->where($option)->save($data);
        return $saveResult === false ? false : true;
    }
}
